<?php
class Db_User
{
	/**
	 * Lấy mảng các rows User theo danh sách IDs dạng 1,2,3,4 ...
	 *
	 * @param string $ids
	 * @return array();
	 */
    static function getUsersByIDs($ids)
    {
        static $users;
        
        if($ids == '')
        {
        	return array();
        }
        
        $arr_users 	= array();
        
        $arr 		= explode(",", $ids);
        $arr_tmp	= array();
        
        foreach ($arr as $uid)
        {
        	if($uid != 0 && $uid != '')
        	{
	        	if(!isset($users[$uid]))
		        {
		        	$arr_tmp[$uid] = $uid;
		        }
		        elseif($users[$uid])
		        {
		        	$arr_users[$uid] = $users[$uid];
		        }
	        }
        }
        
        if($arr_tmp)
        {
        	$ids 	= implode(',',$arr_tmp);
        	
        	$re 	= DB::query("SELECT * FROM user WHERE id IN($ids)", __FILE__ . ' line ' . __LINE__);
        	
        	if($re)
        	{
        		while($user = mysql_fetch_assoc($re))
        		{
        			$users[$user['id']] 	= $user;
        			$arr_users[$user['id']] = $user;
        		}
        	}
        }
            
        return $arr_users;
    }
    
    /**
	 * Lấy mảng các rows User theo user email
	 *
	 * @param string $email
	 * @return array();
	 */
    static function getUsersByEmail($email)
    {
        static $users;
        
        if($email == '')
        {
        	return array();
        }
        
        if(isset($users[$email]))
        {
        	return $users[$email];
        }
        
        $users[$email] 	= DB::select("user", "email='$email'", __FILE__ . ' line ' . __LINE__);
            
        return $users[$email];
    }
}